import path from 'path';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import autoImport from 'unplugin-auto-import/vite';
import components from 'unplugin-vue-components/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';

// https://vitejs.dev/config/
export default defineConfig((args) => {
	const { mode } = args;

	return {
		base: './',
		plugins: [
			vue(),
			autoImport({
				resolvers: [AntDesignVueResolver()],
			}),
			components({
				resolvers: [AntDesignVueResolver({
					importStyle: false
				})],
			}),

			// svg插件配置
			createSvgIconsPlugin({
				// 需要缓存的目标文件夹
				iconDirs: [path.resolve(process.cwd(), 'src/assets/images/svg')],
				// 指定symbolId格式
				symbolId: 'icon-[dir]-[name]',
				/**
				 * 自定义插入位置
				 * @default: body-last
				 */
				// inject?: 'body-last' | 'body-first',
				inject: 'body-last',

				/**
				 * custom dom id
				 * @default: __svg__icons__dom__
				 */
				// customDomId: '__svg__icons__dom__',
			}),
		],
		resolve: {
			alias: {
				'@': path.resolve(__dirname, 'src'),
			},
		},
		define: {
			__DEV__: mode === 'development',
		},
		envPrefix: 'APP_',
	};
});
